import storage from "@/utils/storage";
import { defineStore } from "pinia";
import { ref } from "vue";
import constant from "@/utils/constant";

const useI18nStore = defineStore("i18n", () => {
  const storage_lang = storage.get(constant.language);
  if (!storage_lang) {
    storage.set(constant.language, "zh-Hans");
  }
  const language = ref(storage.get(constant.language));
  
  function setLanguage(lang: string) {
    language.value = lang;
    storage.set(constant.language, lang);
    
  }

  return { language, setLanguage };
});

export default useI18nStore;
